package com.lei.baweiliao.utils;

import android.content.Context;
import android.content.SharedPreferences;

import com.lei.baweiliao.app.MyApp;

/**
 * @ProjectName : BaweiLiao
 * @Author : 雷金泷
 * @Time : 2021/1/14 13:01
 * @Description : 文件描述
 */
public class SpUtils {
    public static final String IS_RED = "is_red";//新的邀请标记
    private static SpUtils instance = new SpUtils();
    private static SharedPreferences msp;

    private SpUtils(){

    }
    public static SpUtils getInstance(){
        if (msp == null){
            msp = MyApp.getmContext().getSharedPreferences("spu", Context.MODE_PRIVATE);
        }
        return instance;
    }
    public void add(String key,Object value){
        if (value instanceof String){
            msp.edit().putString(key,(String) value);
        }else if (value instanceof Boolean){
            msp.edit().putBoolean(key,(Boolean) value);
        }else if (value instanceof Long){
            msp.edit().putLong(key,(Long) value);
        }else if (value instanceof Float){
            msp.edit().putFloat(key,(Float) value);
        }else if (value instanceof Integer){
            msp.edit().putInt(key,(Integer) value);
        }
    }
    public Object get(String key , Object defValue){
        if (defValue instanceof String){
            return msp.getString(key,(String) defValue);
        }else if (defValue instanceof Boolean){
            return msp.getBoolean(key,(Boolean) defValue);
        }else if (defValue instanceof Long){
            return msp.getLong(key,(Long) defValue);
        }else if (defValue instanceof Float){
            return msp.getFloat(key,(Float) defValue);
        }else {
            return msp.getInt(key,(Integer) defValue);
        }
    }
}
